package cn.yangliu.web;

import cn.yangliu.comm.entity.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;


/**
 * 作者 杨柳
 * 创建时间 2017-08-22 01:32
 */
@Controller
public class MyController {


    @GetMapping("/test")
    public String test() {


        return "123123";
    }


    @GetMapping("/repository")
    public String repository() {
        return "123123";
    }

    @Resource
    private AsyncTask asyncTask;

    @GetMapping("/async")
    @ResponseBody
    public String async() {
        asyncTask.test1();
        asyncTask.test2();
        asyncTask.test3();
        return "index";
    }

    @Resource
    AsyncTask2 asyncTask2;

    @GetMapping("/async2")
    @ResponseBody
    public JsonResult async2() throws Throwable {
        LocalTime start = LocalTime.now();
        List<Future<String>> list = Arrays.asList(asyncTask2.test1(),asyncTask2.test2(),asyncTask2.test3());
        for (Future<String> future : list) {
            System.out.println(future.get());
        }
        LocalTime end = LocalTime.now();
        return new JsonResult(Duration.between(start,end));
    }

    @GetMapping("/")
    public String index() {
        return "index";
    }



}
